//
//  XJHTextField.swift
//  PublicPod
//
//  Created by apple on 2022/7/2.
//

import UIKit

public class XJHTextField: UITextField {

    public class func textField(with font:UIFont, textColor:UIColor, plachHolder:String) -> XJHTextField {
        let tf:XJHTextField = XJHTextField()
        tf.font = font
        tf.textColor = textColor
        tf.placeholder = plachHolder
        return tf
    }
    
    // 文本左边距
    fileprivate var _leftTextPadding:CGFloat?
    public var leftTextPadding:CGFloat {
        set {
            _leftTextPadding = newValue
            let leftView:UIView = UIView()
            leftView.frame = CGRect(x: 0, y: 0, width: _leftTextPadding ?? 0.0, height: self.height)
            self.leftView = leftView
            self.leftViewMode = .always
        }
        get {
            return _leftTextPadding ?? 0.0
        }
    }
    
    // 设置圆角
    fileprivate var _cornerSize:CGFloat?
    public var cornerSize:CGFloat {
        set {
            _cornerSize = newValue
            self.layer.cornerRadius = _cornerSize ?? 0
            self.layer.masksToBounds = true
        }
        get {
            return _cornerSize ?? 0.0
        }
    }
    
    // 边框颜色
    fileprivate var _borderColor:UIColor?
    public var borderColor:UIColor {
        set {
            _borderColor = newValue
            self.layer.borderColor = _borderColor?.cgColor
        }
        get {
            return _borderColor ?? .black
        }
    }
    
    // 边框宽度
    fileprivate var _borderWidth:CGFloat?
    public var borderWidth:CGFloat {
        set {
            _borderWidth = newValue
            self.layer.borderWidth = _borderWidth ?? 0.0
        }
        get {
            return _borderWidth ?? 0.0
        }
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
